//
//  BrowseModeController.m
//  CloudWeibo
//
//  Created by CLOUD on 1/14/15.
//  Copyright (c) 2015 Cloud. All rights reserved.
//

#import "BrowseModeController.h"
#import "CONSTS.h"

@interface BrowseModeController ()

@end

@implementation BrowseModeController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"图片浏览模式";
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
    if (indexPath.row == 0) {
        cell.textLabel.text = @"大图";
        cell.detailTextLabel.text = @"大图模式";
    }
    if (indexPath.row == 1) {
        cell.textLabel.text = @"小图";
        cell.detailTextLabel.text = @"小图模式";
    }
    NSInteger mode = [[NSUserDefaults standardUserDefaults] integerForKey:kBrowseMode];
    if (indexPath.row == mode-1) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    int mode = -1;
    if (indexPath.row == 0) {
        mode = LargetBrowseMode;
    }else if (indexPath.row == 1) {
        mode = SmallBrowseMode;
    }
    
    [[NSUserDefaults standardUserDefaults] setInteger:mode forKey:kBrowseMode];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:kReloadWeiBoTableViewByBrowseMode object:nil];
    
    [tableView reloadData];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [_tableView release];
    [super dealloc];
}
@end
